﻿IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_Mail_AddAttachment_V2]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_Mail_AddAttachment_V2];
GO

CREATE PROCEDURE [dbo].[sproc_Mail_AddAttachment_V2]
(
    @MailBodyID     int,
    @FileName       nvarchar(256),
    @VirtualPath    nvarchar(512),
    @FileSize       int,
    @FileAttribute  int
)
AS
BEGIN
SET NOCOUNT ON

IF ( @@TRANCOUNT = 0 )
BEGIN
    RAISERROR(N'This sproc must be executed within an active transaction.', 16, 1);
    RETURN -1;
END

INSERT INTO dbo.UDS_MailAttachment(MailBodyID, FileName, VirtualPath, FileSize, FileAttribute, TimeCreated)
VALUES(@MailBodyID, @FileName, @VirtualPath, @FileSize, @FileAttribute, getdate());

END
GO